"""
金叉：2，死叉：-2  向上：1  向下：-1
支持重复计算，但是要指定timekey，只能向前重复计算
"""
class cross_price:
    def __init__(self):
        self.fx=None
        self.timekey=None
        self.his=[]
    def oncalc(self,fast,slow,timekey=None):
        if fast!=None:
            if slow!=None:
                if timekey != None:
                    if timekey==self.timekey:
                        self.his.pop()
                        self.fx=self.his[-1]
                if self.fx!=None:
                    if self.fx >= 1:
                        if fast < slow:  # 死叉
                            self.fx = -2
                        else:
                            self.fx = 1
                    elif self.fx<=-1:
                        if fast > slow:  # 金叉
                            self.fx = 2
                        else:
                            self.fx = -1
                else:
                    if fast > slow:
                        self.fx = 1
                    elif fast < slow:
                        self.fx = -1
                if timekey != None:
                    self.timekey=timekey
                    self.his.append(self.fx)
                    while len(self.his)>2:
                        self.his.pop(0)
        return self.fx

